var Article = require('../model').Article;

var mod = {
    find: function(userInfo, fn) {
        User.find({userName: userInfo.userName, password: userInfo.password}).
        select(['userName', 'role']).
        exec(fn);
    },

    add: function(info, fn) {
        var article = new Article({
            title: info.title,
            content: info.content,
            user_id: info.user_id,
        });
        article.save(fn);

    },

    // delete article by articleId
    delete: function(articleId, fn) {
        Article.remove({_id: articleId}).exec(fn);
    },

    findAll: function(fn) {
        Article.find({}).
        select(['title', 'content']).
        exec(fn);
    }, 

    getArticleByUserId: function(userId, fn) {
        Article.find({user_id: userId}).
        select(['title', 'content']).
        exec(fn)
    }

}

module.exports = mod;